package com.mediacloud.app.newsmodule.activity.microlive;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;


public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter
{
    public interface ItemClickListener
    {
        void onItemClick(int index, boolean isFromAdaptor, BaseRecyclerAdapter adapter);
    }

    public void setItemClickListener(ItemClickListener listener){
        this.itemClickListener = listener;
    }
    public ItemClickListener itemClickListener;

    List<T> data;
    protected Context context;
    public BaseRecyclerAdapter(Context context)
    {
        this.context=context;
        data=new ArrayList<>();
    }

    public BaseRecyclerAdapter(List<T> data, Context context)
    {
        this.context=context;
        this.data =data;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        if(data!=null)
            this.data = data;
    }

    @Override
    public int getItemCount()
    {
        if(data!=null)
            return data.size();
        return 0;
    }

    public T getItem(int position)
    {
        if(data!=null&&getItemCount()>0&&position<getItemCount())
            return data.get(position);
        return null;
    }


    public void  add(T t){
        if (data == null) data=new ArrayList<>();
        data.add(t);
        notifyDataSetChanged();
    }

    public void addAll(List<T> list){
        if (data == null) data=new ArrayList<>();
        data.addAll(list);
        notifyDataSetChanged();
    }
}